/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uit.qlks.controller.khachhang;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.sql.rowset.WebRowSet;
import uit.ejb.bo.khachhang.KhachHangBORemote;
import uit.ejb.bo.khachhang.KhachHangBORemoteHome;
import uit.ejb.dto.KhachHangDTO;

/**
 *
 * @author Restart
 */
public class KhachHangController {

    private static Context ctx;
    private static KhachHangBORemoteHome phome;
    private static KhachHangBORemote kh;
    public KhachHangController(){

    }

    public static void Register(){
        try{
            ctx = new InitialContext();
            Object obj = ctx.lookup("ejb/KhachHangBO");
            phome = (KhachHangBORemoteHome) PortableRemoteObject.narrow(obj, KhachHangBORemoteHome.class);
            kh=phome.create();
        }
        catch(Exception e){
        }
    }

    public static boolean khachHang_Insert(KhachHangDTO khachhang) {
        try{
            Register();
            return kh.khachHang_Insert(khachhang);
        }catch(Exception e){
            return false;
        }
    }

    public static boolean khachHang_Update(KhachHangDTO khachhang) {
        try{
            Register();
            return kh.khachHang_Update(khachhang);
        }catch(Exception e){
            return false;
        }
    }

    public static boolean khachHang_Delete(String id) {
        try{
            Register();
            return kh.khachHang_Delete(id);
        }catch(Exception e){
            return false;
        }
    }

    public static WebRowSet khachHang_GetById(String id) {
        try{
            Register();
            return kh.khachHang_GetById(id);
        }catch(Exception e){
            return null;
        }
    }

    public static WebRowSet khachHang_GetByTop(String top, String where, String order) {
        try{
            Register();
            return kh.khachHang_GetByTop(top, where, order);
        }catch(Exception e){
            return null;
        }
    }

    public static String khachHang_GetMaxMaKH() {
        try{
            Register();
            return kh.khachHang_GetMaxMaKH();
        }catch(Exception e){
            return null;
        }
    }
}
